﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Data.SqlClient;
using Oracle.DataAccess.Client;
using System.Data.Common;

namespace Petaframe.DataAccess.UnitTest.helpers
{
   public class ClassPropertyAndInfoTestBase
    {
       internal TableInfo expectedTableInfo, expectedTableInfoOracle;
      internal Category testArgument;
      internal DbProviderFactory _oracProvider,_sqlProvider;

       public ClassPropertyAndInfoTestBase()
       {
           _oracProvider = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
           _sqlProvider = DbProviderFactories.GetFactory("System.Data.SqlClient");

         testArgument = new Category();
         expectedTableInfo = new TableInfo() { HasPrimaryKey = true, TableName = new SqlServerEscapeSqlIdentifier().EscapeSqlIdentifier("Categories") };
         expectedTableInfoOracle = new TableInfo() { HasPrimaryKey = true, TableName = new OracleEscapeSqlIdentifier().EscapeSqlIdentifier("Categories") };

         Type objType = testArgument.GetType();
         PropertyInfo categoryIDPropertyInfo = objType.GetProperty("CategoryID");
         PropertyInfo categoryNamePropertyInfo = objType.GetProperty("CategoryName");
         PropertyInfo descriptionPropertyInfo = objType.GetProperty("Description");



         CustomPropertyInfo categoryIDCustomPropertyInfo = new CustomPropertyInfo { AutoIncrement = true, PrimaryKey = true, PropertyName = categoryIDPropertyInfo.Name, PropertyType = categoryIDPropertyInfo.PropertyType, CurrentPropertyDetails = categoryIDPropertyInfo, ParameterInfo = new SqlServerParameterBuilder().CreateParameter(_sqlProvider,0, categoryIDPropertyInfo) };
         CustomPropertyInfo categoryNameCustomPropertyInfo = new CustomPropertyInfo { PropertyName = categoryNamePropertyInfo.Name, PropertyType = categoryNamePropertyInfo.PropertyType, CurrentPropertyDetails = categoryNamePropertyInfo, ParameterInfo = new SqlServerParameterBuilder().CreateParameter(_sqlProvider,1, categoryNamePropertyInfo) };
         CustomPropertyInfo descriptionCustomPropertyInfo = new CustomPropertyInfo { PropertyName = descriptionPropertyInfo.Name, PropertyType = descriptionPropertyInfo.PropertyType, CurrentPropertyDetails = descriptionPropertyInfo, ParameterInfo = new SqlServerParameterBuilder().CreateParameter(_sqlProvider,2, descriptionPropertyInfo) };

         expectedTableInfo.Properties.Add(categoryIDCustomPropertyInfo);
         expectedTableInfo.Properties.Add(categoryNameCustomPropertyInfo);
         expectedTableInfo.Properties.Add(descriptionCustomPropertyInfo);

         expectedTableInfo.PrimaryKeys.Add(categoryIDCustomPropertyInfo);
         expectedTableInfo.TableSqlCommands = new TableQueries(expectedTableInfo);

         CustomPropertyInfo categoryIDCustomPropertyInfoOracle = new CustomPropertyInfo { AutoIncrement = true, PrimaryKey = true, PropertyName = categoryIDPropertyInfo.Name, PropertyType = categoryIDPropertyInfo.PropertyType, CurrentPropertyDetails = categoryIDPropertyInfo, ParameterInfo =  new OracleParameterBuilder().CreateParameter(_oracProvider,0, categoryIDPropertyInfo) };
         CustomPropertyInfo categoryNameCustomPropertyInfoOracle = new CustomPropertyInfo { PropertyName = categoryNamePropertyInfo.Name, PropertyType = categoryNamePropertyInfo.PropertyType, CurrentPropertyDetails = categoryNamePropertyInfo, ParameterInfo = new OracleParameterBuilder().CreateParameter(_oracProvider, 1, categoryNamePropertyInfo) };
         CustomPropertyInfo descriptionCustomPropertyInfoOracle = new CustomPropertyInfo { PropertyName = descriptionPropertyInfo.Name, PropertyType = descriptionPropertyInfo.PropertyType, CurrentPropertyDetails = descriptionPropertyInfo, ParameterInfo = new OracleParameterBuilder().CreateParameter(_oracProvider, 2, descriptionPropertyInfo) };

         expectedTableInfoOracle.Properties.Add(categoryIDCustomPropertyInfoOracle);
         expectedTableInfoOracle.Properties.Add(categoryNameCustomPropertyInfoOracle);
         expectedTableInfoOracle.Properties.Add(descriptionCustomPropertyInfoOracle);

         expectedTableInfoOracle.PrimaryKeys.Add(categoryIDCustomPropertyInfoOracle);
         expectedTableInfoOracle.TableSqlCommands = new TableQueries(expectedTableInfoOracle);
           //Todo:komposite keyler için örnek tablo oluştur ve test et.
           

       }
    }
}
